import {
  Injectable,
  OnModuleInit,
  OnApplicationBootstrap,
  OnModuleDestroy,
  BeforeApplicationShutdown,
  OnApplicationShutdown,
  Inject,
} from '@nestjs/common';
import { CreatePersonDto } from './dto/create-person.dto';
import { UpdatePersonDto } from './dto/update-person.dto';
import { ModuleRef } from '@nestjs/core';

@Injectable()
export class PersonService
  implements
    OnModuleInit,
    OnApplicationBootstrap,
    OnModuleDestroy,
    BeforeApplicationShutdown,
    OnApplicationShutdown
{
  constructor(private readonly moduleRef: ModuleRef) {}

  @Inject('CONFIG_OPTIONS')
  private readonly configOptions: Record<string, any>;

  onModuleInit() {
    console.log('PersonService onModuleInit~');
  }
  onApplicationBootstrap() {
    console.log('PersonService onApplicationBootstrap~');
  }

  onModuleDestroy() {
    console.log('PersonService onModuleDestroy~');
  }

  beforeApplicationShutdown(signal: string) {
    console.log('PersonService beforeApplicationShutdown~', signal);
  }
  onApplicationShutdown() {
    console.log('PersonService onApplicationShutdown~');
  }

  create(createPersonDto: CreatePersonDto): {
    message: string;
    data: { age: number; name: string };
  } {
    return { message: '创建一个新用户', data: createPersonDto };
  }

  findAll() {
    return `This action returns all person`;
  }

  findOne(id: number) {
    return `This action returns a #${id} person, ${JSON.stringify(this.configOptions)}`;
  }

  update(id: number, updatePersonDto: UpdatePersonDto) {
    return `This action updates a #${id} person`;
  }

  remove(id: number) {
    return `This action removes a #${id} person`;
  }
}
